/*
 * Inspection.java
 *
 * Created on 05. Juni 2007, 03:06
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package sbc.fact;

import sbc.repos.Feature;
import sbc.repos.Sensor;
import corso.lang.*;

/**
 *
 * @author mustermark
 */
public class Inspection extends Task<Sensor> {
    
    private Feature education;
    private CorsoVarOid sensorAtInspectionOid;
    private Factory fact;
    
    public Inspection() {}
    /**
     * Creates a new instance of Inspection
     */
    public Inspection(String name, String factory, Feature f) {
        super(name);
        education = f;
        /*try {
            fact.getStaff().getOid().writeShareable (this, CorsoConnection.INFINITE_TIMEOUT);
        }  catch (CorsoException eSys1) {   
            System.out.println (eSys1);
            System.exit (-1);
        }*/
                
    }
    
    public boolean isEducatedFor(Feature f) {
        return education == f;
    }
    
    public void workOn(Sensor s) throws WorkException {}
 
    public void write (CorsoData data) throws CorsoDataException {
        if(sensorAtInspectionOid != null) {
            data.putStructTag ("Inspector", 3);
            data.putString(getUID());
            data.putString(education.toString());
            data.putShareable(sensorAtInspectionOid);

        } else {
            data.putStructTag ("Inspector", 2);
            data.putString(getUID());
            data.putString(education.toString());
        }
        
    }
    public void read (CorsoData data) throws CorsoDataException {
        StringBuffer structName = new StringBuffer ();
        int arity = data.getStructTag (structName);
        if (!structName.toString().equals("Inspector"))
            throw new CorsoDataException ();
        if(arity == 2) {
            setUID(data.getString());
            education = Feature.valueOf(data.getString().toUpperCase());
        } else if(arity == 3) { 
            setUID(data.getString());
            education = Feature.valueOf(data.getString().toUpperCase());
            data.getShareable(sensorAtInspectionOid);
        } else throw new CorsoDataException ();
        
    }
    
    public static void main (String [] args) {
        if (args.length != 3)
        {
            System.out.println ("CALL: Inspector <name> <factory> <featureEducatedFor>");
            System.exit (-1);
        } else {
            try {
                Feature f = Feature.valueOf(args[3].toUpperCase());
                new Inspection(args[0], args[1], f);
            } catch(Exception e) {
                System.out.println (args[3] + " is not a Feature. Features are:");
                for(Feature f : Feature.values()) System.out.print(f +", ");
                System.out.println();

            }
        }

        
    }
}
